package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import java.util.Objects;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.AccountWhiteListAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.scene.attr.OperateInstAttrService;

@Service
@AttrHandler(AccountWhiteListAttrHandler.class)
public class AccountWhiteListAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {
    @Autowired
    OperateInstAttrService operateInstAttrService;

    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        //卡级白名单
        KiteAttr cardWhiteListAttr = inst.getAttr("200004022");
        //白名单号码
        KiteAttr whiteListNbrAttr = inst.getAttr("200003695");
        if (Objects.isNull(cardWhiteListAttr)) {
            return;
        }

        if ("100006427".equals(attr.getValue())) {
            if (!KeyConsts.PROD_ATTR_SHOW_TYPE_E.equals(attr.getShowType())) {
                operateInstAttrService.setAttrValue(inst, "200004022", "100006428", data.getSceneInstId(), null);
            }
            if (!KeyConsts.PROD_ATTR_SHOW_TYPE_E.equals(cardWhiteListAttr.getShowType())) {
                cardWhiteListAttr.setValue("100006428");
                cardWhiteListAttr.setValueDesc("主叫白名单");
            }
            if (!KeyConsts.PROD_ATTR_SHOW_TYPE_E.equals(attr.getShowType()) && !KeyConsts.PROD_ATTR_SHOW_TYPE_E.equals(cardWhiteListAttr.getShowType())) {
                whiteListNbrAttr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_D);
            }
        }
        else {
            if (!KeyConsts.PROD_ATTR_SHOW_TYPE_E.equals(attr.getShowType()) && !KeyConsts.PROD_ATTR_SHOW_TYPE_E.equals(cardWhiteListAttr.getShowType())) {
                whiteListNbrAttr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_D);
            }
        }

        //帐户级白名单和卡级白名单都为【不开通】时,白名单号码不展示
        if ("100006427".equals(attr.getValue()) && "100006427".equals(cardWhiteListAttr.getValue())) {
            whiteListNbrAttr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_E);
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }
}
